<?php
/**
 * 1.帖子
 */
namespace app\topic\controller;
use app\common\controller\HomeCommon;
use think\Request;
class Index extends HomeCommon
{
	/**
	 * 1、帖子列表
	 * @return \think\response\Json
	 */
    public function index()
    {
    	if(Request::instance()->isPost()){
    		
    		$where="1=1 and a.status=1 ";
    		$topic_id=request()->param("topic_id", 0, 'intval');
    		if($topic_id){
    			$where.=" and a.topic_id=".$topic_id;
    		}
    		/* if(input('token')){
    			$token=input('token');
    			//验证token
    			$result=$this->check_token($token);
    			
    			if($result['errcode']!=0){
    				
    				return json(['errcode'=>'10001','msg'=>'token错误！','data'=>[]]);die;
    			}
    			$where.=" and a.user_id=".$this->user_id;
    			//获得当前用户加入的园区
    			$park_list=db('users_parks')->field('parkid')->where(['status'=>1,'user_id'=>$this->user_id])->select();
    			if(!empty($park_list)){
    				$park_str="";
    				$park_arr=[];
    				foreach ($park_list as $val){
    					$park_arr[]=$val['parkid'];
    				}
    				$park_str=implode(',',$park_arr);
    				$where.=" and concat(',',a.park_id,',') regexp concat(',(',replace('$park_str',',','|'),'),') ";
    			}
    		}  */
    		
    		
    		
    		$list=db('topic_content')
    		->alias('a')
    		//->field('a.id activity_id,a.title,a.desc,a.images,a.time,a.address,b.images headimg,b.username')
    		//->join('users b','a.user_id=b.id')
    		->where($where)
    		->order('a.id desc')
    		->paginate(15);
    		
    		return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$list]);
    	}
    	
    }
    /**
     * 话题类别列表
     */
    public function type_list(){
    	if(Request::instance()->isPost()){
    		
    		$where="1=1 and status=1 ";
    		
    		$list=db('topic_type')
    		->field('*')
    		->where($where)
    		->order('id desc')
    		->paginate(15);
    		
    		return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$list]);
    	}
    }
    /**
     * 话题列表
     */
    public function topic_list(){
    	if(Request::instance()->isPost()){
    		
    		$where="1=1 and status=1 ";
    		if(!empty(input('type_id'))){
    			$where.=" and type_id=".input('type_id');
    		}
    		$list=db('topic')
    		->field('*')
    		->where($where)
    		->order('id desc')
    		->paginate(15);
    		
    		return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$list]);
    	}
    }
}
